package com.foreknow.demo8;

/**
 * 静态变量:可以被多个对象共享
 * 作用：可以作为累加器来使用
 */
public class StaticVar {
    private static int k;
    public static int i;
    public StaticVar() {
        i++;
        System.out.println(i);
    }

    public void method() {
        i = 12;
    }

    public static void method1() {
        k = 15;
    }

    public static void main(String[] args) {
        StaticVar staticVar1 = new StaticVar();
        StaticVar staticVar2 = new StaticVar();
        StaticVar staticVar3 = new StaticVar();
        StaticVar staticVar4 = new StaticVar();
    }
}
